import { assert, beforeAll, describe, test } from 'vitest';
import { CHECK_MODE, testCaseCheck } from '../common/testCommon';
import NoCondAssignDsl from '../../../../src/checker/dsl/NoCondAssignDsl';
import path from 'path';
import { CheckEntry, Rule } from '../../../../src/Index';

let realPath: string = '';
let checkEntry: CheckEntry;

beforeAll(async () => {
  const rule: Rule = new Rule('');
  checkEntry = await testCaseCheck(
    './test/unittest/sample/NoCondAssignDsl',
    rule,
    CHECK_MODE.FILE2CHECK,
    NoCondAssignDsl,
    false,
    true,
  );
  realPath = checkEntry.scene.getRealProjectDir();
});

describe('NoCondAssignDslTest', () => {
  test('NoCondAssignDslTest_001', () => {
    const detectFile = path.join(realPath, 'NoCondAssignDslReport.ts');
    const expectReportList = ['3%3'];
    const detectFileReport = checkEntry.fileChecks.find(fileCheck => fileCheck.arkFile.getFilePath() === detectFile);
    assert.isDefined(detectFileReport, 'The file path is invalid.');
    assert.equal(detectFileReport?.issues.length, expectReportList.length, 'The number of reported lines does not match.');
    detectFileReport?.issues.forEach((issue, index) => {
      assert.include(issue.defect.fixKey, expectReportList[index], `The issue at ${expectReportList[index]} is not found.`);
    });
  });

  test('NoCondAssignDslTest_002', () => {
    const detectFile = path.join(realPath, 'NoCondAssignDslNoReport.ts');
    const detectFileReport = checkEntry.fileChecks.find(fileCheck => fileCheck.arkFile.getFilePath() === detectFile);
    assert.equal(detectFileReport?.issues.length, 0, 'The number of reported lines should be 0.');
  });
});
